package com.github.customFilter;

import java.util.LinkedList;

/**
 * 移除方式实现的过滤器链
 * Created by zhangcheng03 on 2021-6-29 9:40.
 */
public class FilterChainImpl2 implements FilterChain {
    LinkedList<Filter> listfilter = new LinkedList<Filter>();

    public void append(Filter filter) {
        listfilter.add(filter);
    }

    @Override
    public void execute() {
        if (hasNextFilter())
            nextFilter().doFilter(this);
        else {
            System.out.println("执行目标方法");
        }
    }

    public boolean hasNextFilter() {
        return listfilter.size() > 0;
    }

    public Filter nextFilter() {
        return listfilter.pop();
    }
}